﻿using Model;
using BLL;
using System.Data;
using System;

namespace NCRE学生考试端V1._0.PPT操作题类
{
    /// <summary>
    /// PPT判分助手类-姜晶-2018年4月4日
    /// </summary>
    public class PptJudgeHelper
    {
        /// <summary>
        /// 考生文件
        /// </summary>
        private static string file = string.Format("D:\\" + MyInfo.MystudentID() + "\\计算机一级考生文件\\" + MyInfo.MyPaperType() + "卷\\Pptkt\\PPT" + MyInfo.MyPaperType().Trim() + ".pptx");
        /// <summary>
        /// PPT根据题型判分
        /// </summary>
        public void PptJudgebyQuestionFlag()
        {
            PptQuestionEntityBLL pptquestionbll = new PptQuestionEntityBLL();
            PptQuestionEntity pptinfo = new PptQuestionEntity();
            PptQuestionRecordEntity PPTstudent = new PptQuestionRecordEntity();
            PPTstudent.StudentID = FrmLogin.studentID;
            pptinfo.PaperType = MyInfo.MyPaperType();
            //从题库中选出试题信息
            DataTable dt = pptquestionbll.LoadPptQuestion(pptinfo);

            if (System.IO.File.Exists(file))
            {
                #region 根据题型判分
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    pptinfo.QuestionFlag = dt.Rows[i]["QuestionFlag"].ToString().Trim();
                    pptinfo.PlaceFlag = dt.Rows[i]["PlaceFlag"].ToString().Trim();
                    //根据题型判分
                    PptJudege pptjudge = new PptJudege();
                    pptjudge.Judge(pptinfo);
                }
                #endregion
            }
            else
            {
                #region 考生未答题
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    PptQuestionRecordEntity pptstudent = new PptQuestionRecordEntity();
                    pptstudent.StudentID = FrmLogin.studentID;
                    pptstudent.PaperType = MyInfo.MyPaperType();
                    pptstudent.TimeStamp = MyInfo.TimeTamp();
                    pptstudent.QuestionID = Convert.ToDouble(dt.Rows[i]["QuestionID"]);
                    pptstudent.ExamAnswer = "本地无考生文件";
                    pptstudent.Fration = "0";
                    PptLoadinfo.list.Add(pptstudent);
                }
                #endregion
            }
            //考生文件及分数更新入库
            pptquestionbll.ReturnScore(PptLoadinfo.list, PPTstudent);
        }
        /// <summary>
        /// 将数据库的坐标字符串转换成int数组
        /// </summary>
        /// <param name="placeflag">数据库中元素坐标参数:（a,b）PPT第a张的第b个元素</param>
        /// <returns>返回数组[0]是Slides,[1]是Shapes</returns>
        public int[] PlaceFlag(string placeflag)
        {
            string[] a = placeflag.Split(',');
            int[] b = { int.Parse(a[0]), int.Parse(a[1]) };
            return b;
        }
    }
}
